home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000217_icon-group-sender _Thu Oct 21 08:00:13 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id HAA16777
for icon-group-addresses; Thu, 21 Oct 1999 07:58:13 -0700 (MST)
Message-Id: <199910211458.HAA16777@baskerville.CS.Arizona.EDU>
Date: Wed, 20 Oct 1999 19:21:24 -0700
From: Blake Chapman <blakec@pacbell.net>
Subject: List subscription insert/removal
To: icon-group@optima.CS.Arizona.EDU
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Icon Project,
I am trying to figure out how to insert a new element into a list,
and remove an element from the middle of a list (not the end).
In answer to this question previously Gordon Peterson sent
a reply. I tried what he said and it doesn't work.
My original question, that he answered, was
"I find no routines to pluck one element out of the middle of a list, or insert
one in. Are there such routines?".
His answer was:
"Perhaps not, since those functions are really pretty trivial (you can use
subscript ranges to specify sublists, making that kind of thing a simple
expression).".
I assume he meant that I can insert an element into a list the same way
I can insert a character into a string variable. So I tried it, 4 ways; none
of them worked, they all produce a run-time error and abort. Here is
the program. Though I use mere charactes or 1-char strings as list
elements, it is just to try out list manipulation...
procedure main()
local s # it will be a list
s:= ["a", "b", "c", "d"]
WriteL(s) # this writes "abcd" as it should
# Next, I want to insert "x" as a list element between "b" and "c" ....
# didn't work: s[3:3]:="x"
# didn't work: s[3:3] := ["x"]
# didn't work: s[3+:0] := ["x"]
s[3+:0] := "x" # didn't work; I get a run-time error and program abort
WriteL(s)
end
procedure WriteL(L)
local i, len
len := *L
i := 1
while i <= len do { writes(L[i]) ; i +:= 1 }
write()
end
I get the following error message when I run the above:
Run-time error 111
File E:\icon\wsource\sublist.icn; Line 28 [the line: s[3+:0] := "x" ]
variable expected
offending value: list_3 = []
Traceback:
main()
{list_3 = [] := "x"} from line 28 in E:\icon\wsource\sublist.icn
Can you tell me how to accomplish what I want?
Thank You,
Blake Chapman